<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  var a = 10;

  function fn(){
    var b = 20;

    function fun(){
      var c = 30;

      console.log(a);
      console.log(b);
      console.log(c);
    }
    fun();

    console.log(a);
    console.log(b);
    // console.log(c);

  }
  fn();


  console.log(a);
  // console.log(b);
  // console.log(c);


  console.log("=========")


  var x = 10;
  function box1(){
    // var x = 20;
    function box2(){
      // var x = 30;
      function box3(){
        // var x = 40;
        console.log("这是在box3内的x:" + x);
      }
      box3();
      console.log("这是在box2内的x:" + x);
    }
    box2();
    console.log("这是在box1内的x:" + x);
  }
  box1();
  console.log("这是在全局的x:" + x);

  
  console.log("=========")

 

  // var y = 10;
  function box4(){
    // var y = 20;
    function box5(){
      // var y = 30;
      function box6(){
        // var y = 40;

        y = "hello";

        console.log("这是在box6内的y:" + y);
      }
      box6();
      console.log("这是在box5内的y:" + y);
    }
    box5();
    console.log("这是在box4内的y:" + y);
  }
  box4();
  console.log("这是在全局的y:" + y);



  console.log("=========")



  function foo(){
    var z = "hello";
    function f1(){
      console.log(z)
    }
    function f2(){
      console.log(z)
    }
    function f3(){
      console.log(z)
    }
    f1();
    f2();
    f3();
  }
  foo();



  console.log("=========");



  // 匿名函数：立即执行
  // 意义：创建一个新作用域

  ;(function(){
    console.log("hahahaha")
  })();

  






</script>
</html>